﻿// <copyright file="IModMatcherHandler.cs" company="SingularityShift">
// Copyright (c) 2009 SingularityShift.com
// </copyright>
// <author>Ben McClure</author>
// <email>ben@singularityshift.com</email>
// <date>2009-08-14</date>
// <summary>A public interface which defines an object that handles matches found with an IModMatcher</summary>
namespace GameLib.Games
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GameLib.Games.Util;

    /// <summary>
    /// Defines the action to be taken when handling a ModMatcher match
    /// </summary>
    public enum ModMatcherHandlerAction
    {
        /// <summary>
        /// <para>Enables (or keeps enabled) the mod this matcher belongs to.</para>
        /// <para>This may enable or disable the matching mod(s) as necessary.</para>
        /// </summary>
        EnableMod,

        /// <summary>
        /// <para>Enables (or keeps enabled) the matching mod(s) found by this matcher.</para>
        /// <para>This may enable or disable the matcher's parent mod, or one or more matching mod(s).</para>
        /// </summary>
        EnableMatchingMod,

        /// <summary>
        /// <para>Disables (or keeps disabled) the mod this matcher belongs to.</para>
        /// <para>This may enable or disable the matching mod(s) as necessary.</para>
        /// </summary>
        DisableMod,

        /// <summary>
        /// <para>Disables (or keeps disabled) the mod(s) found by this matcher.</para>
        /// <para>This may enable or disable the matcher's parent mod, or one or more matching mod(s).</para>
        /// </summary>
        DisableMatchingMod,

        /// <summary>
        /// Does not enable or disable any mods. This effectively makes the match unhandled.
        /// </summary>
        DoNothing
    }

    /// <summary>
    /// Defines a class which can handle (resolve) the matches found by an IModMatcher.
    /// </summary>
    public interface IModMatcherHandler<T> where T : IMod
    {
        /// <summary>
        /// Sets whether calling the Handle method of this handler should actually handle a match (used to temporarily disable the handler)
        /// </summary>
        event EventHandler<ModMatcherHandlerEventArgs> BeforeHandleEvent;

        /// <summary>
        /// Thrown when this match is handled.
        /// </summary>
        event EventHandler<ModMatcherHandlerEventArgs> AfterHandleEvent;

        /// <summary>
        /// Required for any IModMatcherHandler. This method handles (or not) the match.
        /// </summary>
        /// <param name="matcher">The matcher that was used to match with</param>
        /// <param name="conflictingMod">The IMod that was found as a match</param>
        /// <returns>The ModMatcherHandlerAction that was performed</returns>
        ModMatcherHandlerAction Handle(IModMatcher matcher, T mod);

        /// <summary>
        /// The sole function required for any IModMatcherHandler. This method handles (or not) the match.
        /// </summary>
        /// <param name="list">A list returned from a relevant IModMatcherResolver.</param>
        /// <returns>The ModMatcherHandlerAction that was performed (or the latest one, if several)</returns>
        ModMatcherHandlerAction HandleList(IList<MatcherStruct<T>> list);
    }
}
